(function () {
    var upComingEventDetailContext = {};
    upComingEventDetailContext.Templates = {};
    upComingEventDetailContext.Templates.Fields = {
        'Body': { 'View': UpComingEventDetail },
        'Author': { 'View': CAuthorName }

    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(upComingEventDetailContext);
})();

function UpComingEventDetail(ctx) {
    if ($("#contentBox") !== null) {
        $("#contentBox").removeClass("col-sm-12 col-md-12 col-lg-12");
        $("#contentBox").addClass("col-sm-10 col-md-10 col-lg-10");
    }

    var title = ctx.CurrentItem.Title;
    var body = ctx.CurrentItem.Body;
    var imageurl = ctx.CurrentItem.PublishingPageIcon;
    var imgUrl = '';

    if (imageurl != null && $(imageurl).find('img').length > 0 && $(imageurl).find('img').attr('src') != "") {
        imgUrl = $(imageurl).find('img').attr('src');
    }
    else {
        imgUrl = '/teams/OurVoiceHN/Style Library/Images/default_image.gif';
    }

    var ret = "<div class='row'>" +
        "<div class='upcomingImage col-sm-6 col-md-6 col-lg-6'><img class='img-responsive' src='" + imgUrl + "'></div>" +
        "<div class='upcomingContent col-sm-6 col-md-6 col-lg-6'>" + body + "</div>" +
        "</div>";
    return ret;
}
function CAuthorName(ctx) {
    if (ctx.CurrentItem.AuthorName != null || ctx.CurrentItem.AuthorName != undefined || ctx.CurrentItem.AuthorName != "")
        return ctx.CurrentItem.AuthorName;
    else {
        return ctx.CurrentItem.Author;
    }
}